fix(backpack-api): reject with response.statusCode instead of response.status#10072
Open
Chessing234 wants to merge 1 commit into
Conversation
…s undefined) All four backpack xhr callbacks branch on 'response.statusCode !== 200' but then call 'reject(new Error(response.status))'. The xhr npm package exposes the HTTP code as 'statusCode', not 'status', so every rejection surfaced an Error whose message was the literal string 'undefined', hiding the actual failure code from callers/logging. Switch the error constructor to use 'response.statusCode' to match the check on the same line.
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Every backpack xhr callback rejects with `new Error(response.status)`, but the surrounding check is `response.statusCode !== 200`. As a result, every non-2xx response (and every error path) bubbles up as `Error: undefined` to callers, hiding the real HTTP code from logs and UI.
```js
if (error || response.statusCode !== 200) {
return reject(new Error(response.status)); // response.status === undefined
}
```
Root cause
This file uses the `xhr` npm package, whose response object exposes the HTTP code as `statusCode`, not `status`. The status check on the same line uses the correct name; only the error-construction half of each pair was wrong. Same copy-paste typo across all four functions (`getBackpackContents`, `saveBackpackObject`, `deleteBackpackObject`, `fetchAs`).
Fix
Pass `response.statusCode` into the `Error` so the rejection actually carries the HTTP code. Mechanical 4-line change matching the check immediately above each line.